﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Top.PointStore.SyncDataBaseService
{
    class Program
    {
        private static DateTime lastUpdateTime = DateTime.Now.Date.AddDays(-1);
        static void Main(string[] args)
        {
            FiveMinutes();
        }

        public static void OneDay()
        {
            Console.WriteLine("程序正在启动...");
            var task = new Task(() =>
            {
                while (true)
                {
                    if (DateTime.Now.Date > lastUpdateTime)
                    {
                        lastUpdateTime = DateTime.Now.Date;
                        Console.WriteLine("开始同步 T_BrokerCompany 数据量");
                        DataBaseSyncManager.SyncDataCount_BrokerCompany();

                        Console.WriteLine("开始比对 T_BrokerCompany 数据");
                        DataBaseSyncManager.SyncDataValue_BrokerCompnay_Part();

                        Console.WriteLine("开始同步 T_Broker 数据量");
                        DataBaseSyncManager.SyncDataCount_Broker();

                        Console.WriteLine("开始比对 T_Broker 数据");
                        DataBaseSyncManager.SyncDataValue_Broker_Part();

                        Console.WriteLine("开始同步 S_Admin 数据量");
                        DataBaseSyncManager.SyncDataCount_Admin();

                        Console.WriteLine("开始比对 S_Admin 数据");
                        DataBaseSyncManager.SyncDataValue_Admin_Part();

                        Console.WriteLine("开始同步 T_PointRule 数据量");
                        DataBaseSyncManager.SyncDataCount_PointRule();

                        Console.WriteLine("开始比对 T_PointRule 数据");
                        DataBaseSyncManager.SyncDataValue_PointRule_Part();

                        Console.WriteLine("同步数据完毕 日期：{0}", DateTime.Now);
                    }
                    Thread.Sleep(3600000);
                }
            });
            task.Start();
            Console.WriteLine("程序已开启");
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "end")
                {
                    return;
                }
                else
                {
                    Console.WriteLine("结束请输入end");
                }
            }
        }

        public static void FiveMinutes()
        {
            Console.WriteLine("程序正在启动...");
            var task = new Task(() =>
            {
                while (true)
                {
                    if (true)//(DateTime.Now - lastUpdateTime).Minutes >= 5
                    {
                        lastUpdateTime = DateTime.Now.Date;
                        Console.WriteLine("开始同步 T_BrokerCompany 数据量");
                        DataBaseSyncManager.SyncDataCount_BrokerCompany();

                        Console.WriteLine("开始比对 T_BrokerCompany 数据");
                        DataBaseSyncManager.SyncDataValue_BrokerCompnay_Part();

                        Console.WriteLine("开始同步 T_Broker 数据量");
                        DataBaseSyncManager.SyncDataCount_Broker();

                        Console.WriteLine("开始比对 T_Broker 数据");
                        DataBaseSyncManager.SyncDataValue_Broker_Part();

                        Console.WriteLine("开始同步 S_Admin 数据量");
                        DataBaseSyncManager.SyncDataCount_Admin();

                        Console.WriteLine("开始比对 S_Admin 数据");
                        DataBaseSyncManager.SyncDataValue_Admin_Part();

                        //Console.WriteLine("开始同步 T_PointRule 数据量");
                        //DataBaseSyncManager.SyncDataCount_PointRule();

                        //Console.WriteLine("开始比对 T_PointRule 数据");
                        //DataBaseSyncManager.SyncDataValue_PointRule_Part();

                        Console.WriteLine("同步数据完毕 日期：{0}", DateTime.Now);
                    }
                    Thread.Sleep(300000);
                }
            });
            task.Start();
            Console.WriteLine("程序已开启");
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "end")
                {
                    return;
                }
                else
                {
                    Console.WriteLine("结束请输入end");
                }
            }
        }

        public static void TwoTimeSync()
        {
            Console.WriteLine("程序正在启动...");
            var task = new Task(() =>
            {
                while (true)
                {
                    if ((DateTime.Now.Date > lastUpdateTime)&&(DateTime.Now.Hour>=2))
                    {
                        lastUpdateTime = DateTime.Now.Date;
                        Console.WriteLine("开始同步 T_BrokerCompany 数据量");
                        DataBaseSyncManager.SyncDataCount_BrokerCompany();

                        Console.WriteLine("开始比对 T_BrokerCompany 数据");
                        DataBaseSyncManager.SyncDataValue_BrokerCompnay_Part();

                        Console.WriteLine("开始同步 T_Broker 数据量");
                        DataBaseSyncManager.SyncDataCount_Broker();

                        Console.WriteLine("开始比对 T_Broker 数据");
                        DataBaseSyncManager.SyncDataValue_Broker_Part();

                        Console.WriteLine("开始同步 S_Admin 数据量");
                        DataBaseSyncManager.SyncDataCount_Admin();

                        Console.WriteLine("开始比对 S_Admin 数据");
                        DataBaseSyncManager.SyncDataValue_Admin_Part();

                        Console.WriteLine("开始同步 T_PointRule 数据量");
                        DataBaseSyncManager.SyncDataCount_PointRule();

                        Console.WriteLine("开始比对 T_PointRule 数据");
                        DataBaseSyncManager.SyncDataValue_PointRule_Part();

                        Console.WriteLine("同步数据完毕 日期：{0}", DateTime.Now);
                    }
                    Thread.Sleep(300000);
                }
            });
            task.Start();
            Console.WriteLine("程序已开启");
            while (true)
            {
                string input = Console.ReadLine();
                if (input == "end")
                {
                    return;
                }
                else
                {
                    Console.WriteLine("结束请输入end");
                }
            }
        }
    }
}
